home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.1 (Developer) [x86] / NeXT Step 3.1 Intel dev.cdr.dmg / NextDeveloper / Examples / IndexingKit / ToDoList / ListController.m < prev    next >
Encoding:
Text File  |  1993-02-16  |  2.9 KB  |  129 lines

  1. /*
  2. ListController.m - Copyright (c) 1992 NeXT Computer, Inc.
  3.  
  4. You may freely copy, distribute and reuse the code in this example.
  5. NeXT Computer, Inc. disclaims any warranty of any kind, expressed or implied, 
  6. as to its fitness for any particular use.
  7. */
  8.  
  9. #import "ListController.h"
  10. #import "MainDelegate.h"
  11. #import "DailyBread.h"
  12.  
  13. #import <appkit/appkit.h>
  14. #import <dbkit/dbkit.h>
  15. #import <indexing/indexing.h>
  16.  
  17. #define NUMOFITEMS 7
  18.  
  19. @implementation ListController
  20.  
  21. - initForDateString:(const char *)theDate andRecordManager:theRM
  22. {
  23.     id            cursor;
  24.     char        path[MAXPATHLEN + 1];
  25.     
  26.     if ([[NXBundle mainBundle] getPath:path forResource:"ListForDay" ofType:"nib"])
  27.     [NXApp loadNibFile:path owner:self];
  28.     
  29.     _theDate = (char *)malloc(strlen(theDate)+2);
  30.     strcat(strcpy(_theDate, theDate), " ");
  31.     _records = theRM;
  32.     cursor = [_records cursorForAttributeNamed:"TheDate"];
  33.     if ([cursor setKey:(void *)_theDate andLength:(strlen(_theDate) + 1)] == YES) {
  34.     _theHandle = [cursor setFirstHandle];
  35.     dailyBread = [_records readRecord:_theHandle fromZone:[self zone]];
  36.     } else {
  37.     dailyBread = [[DailyBread alloc] initForDate:_theDate];
  38.     _theHandle = [_records addRecord:dailyBread];
  39.     }
  40.  
  41.     [window setTitle:_theDate];
  42.     [tableView setDataSource:self];
  43.     [commentVector setIdentifier:dailyBread];
  44.     doneObj = [[Object alloc] init];
  45.     [doneVector setIdentifier:doneObj];
  46.     [tableView display];
  47.     [window makeKeyAndOrderFront:self];
  48.     return self;
  49. }
  50.  
  51. - finishItem:sender
  52. {
  53.     return self;
  54. }
  55.  
  56. - free
  57. {
  58.     [dailyBread free];
  59.     return [super free];
  60. }
  61.  
  62. - (char *)theDate
  63. {
  64.     return _theDate;
  65. }
  66.  
  67. - windowWillClose:sender
  68. {
  69.     [self saveTheRecord:sender];
  70.     [[NXApp delegate] windowWillDisappear:self];
  71.     return self;
  72. }
  73.  
  74. - orderUp:sender
  75. {
  76.     [[tableView window] makeKeyAndOrderFront:sender];
  77.     return self;
  78. }
  79.  
  80. - saveTheRecord:sender
  81. {
  82.     id                  storeFile;
  83.     unsigned            handle;
  84.  
  85.     [_records getBlock:&handle andStore:&storeFile];
  86.  
  87.     // this is *VERY* important to be sure the changes make it into the store. 
  88.     [_records replaceRecord:_theHandle with:dailyBread];
  89.     [storeFile commitTransaction];
  90.  
  91.     return self;
  92. }
  93.  
  94. // these are the DataSource methods needed by the tableView.
  95.  
  96. - (unsigned int)rowCount
  97. {
  98.     return 7;
  99. }
  100.  
  101. - getValueFor:identifier at:(unsigned int)aPosition into:aValue
  102. {
  103.     if (identifier == dailyBread)
  104.     [aValue setStringValue:[dailyBread number:(int)aPosition]];
  105.  
  106.     if (identifier == doneObj)
  107.     [aValue setStringValue:[dailyBread done:(int)aPosition] ? "Y" : ""];
  108.  
  109.     return self;
  110. }
  111.  
  112. - setValueFor:identifier at:(unsigned int)aPosition from:aValue
  113. {
  114.     if (identifier == dailyBread)
  115.     [dailyBread setNumber:(int)aPosition to:[aValue stringValue]];
  116.  
  117.     if (identifier == doneObj)
  118.     [dailyBread setDone:(int)aPosition to:strcmp([aValue stringValue], "")];
  119.  
  120.     return self;
  121. }
  122.  
  123. - pullUndoneForward:sender
  124. {
  125.     return self;
  126. }
  127.  
  128. @end
  129.